package org.iabako.client.ui.form.extranet.signup;

import com.google.gwt.core.client.GWT;
import com.google.gwt.event.dom.client.ClickEvent;
import com.google.gwt.event.dom.client.ClickHandler;
import com.google.gwt.uibinder.client.UiBinder;
import com.google.gwt.uibinder.client.UiField;
import com.google.gwt.user.client.ui.Composite;
import com.google.gwt.user.client.ui.HTMLPanel;
import org.iabako.client.ui.layout.field.LabelText;
import org.iabako.client.ui.layout.widget.paypal.PayPalForm;
import org.iabako.client.ui.layout.widget.validation.ValidationMessage;
import org.iabako.shared.entity.enumeration.SignUpStep;

/**
 * Created by jose on 12/12/14.
 */
public class SignUpPaymentForm extends Composite {

    interface MyUiBinder extends UiBinder<HTMLPanel, SignUpPaymentForm> {
    }

    protected MyUiBinder binderForm = GWT.create(MyUiBinder.class);

    @UiField
    LabelText goBack;
    @UiField
    PayPalForm payPalForm;

    SignUpForm signUpForm;

    public SignUpPaymentForm() {
        initWidget(binderForm.createAndBindUi(this));

        goBack.getLabel().addClickHandler(new ClickHandler() {
            public void onClick(ClickEvent event) {
                ValidationMessage.getFirstFromDOM().clear();

                signUpForm.goTo(SignUpStep.signUpEmailValidation);
            }
        });
    }

    public void setSignUpForm(SignUpForm signUpForm) {
        this.signUpForm = signUpForm;
    }

    @Override
    public void setVisible(boolean visible) {
        super.setVisible(visible);

        if (!visible) {
            return;
        }
        payPalForm.initialize(signUpForm.getUser().getUserPayPalToken().getTransactionId());
    }
}
